<?php
namespace App\Http\Middleware;
use Closure;
use JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use App\OrderRecord;


class finishOrder
{
  /**
   *@author Arius
   *@function tel validate
   *
   *
   */
    public function handle($request, Closure $next)
    {
      $token = JWTAuth::getToken();
  
      //get the user infomation
      $user_json = JWTAuth::toUser($token);
  
      $user = json_decode($user_json, true);

      $order=OrderRecord::where(['userphone'=>$user['tel'],'isAccept'=>4])->get;	
      //如果订单没有被接
        if ($order) {
                return $next($request);
        }
        return response()->json([
            'code' => '58008',
            'message' => 'order not finish,You have can not use this API',
            'data' => '',
        ]);
    }
}
